package org.example.iocdemo;

import org.example.iocdemo.component.UserComponent;
import org.example.iocdemo.configuration.UserConfiguration;
import org.example.iocdemo.controller.UserController;
import org.example.iocdemo.repository.User;
import org.example.iocdemo.repository.UserRepository;
import org.example.iocdemo.service.UserService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
public class IocDemoApplication {

    public static void main(String[] args) {
        // 获取 Spring 上下文对象
        ApplicationContext context = SpringApplication.run(IocDemoApplication.class, args);
        // 从 Spring 上下文中获取对象
        // 通过类的字节码文件获取 bean
        UserController bean = context.getBean(UserController.class);
        // 使用对象 调用方法
//        bean.sayHello();
        bean.sayHi();
        // 通过类名称获取 bean
//        UserService userService = (UserService) context.getBean("userService");
//        userService.sayHello();

        // 根据类型获取 bean
//        UserController userController1 = context.getBean(UserController.class);
//        // 根据名称获取 bean
//        UserController userController2 = (UserController) context.getBean("userController");
//        // 根据 类型 + 名称 获取 bean
//        UserController userController3 = context.getBean("userController", UserController.class);
//
//        userController1.sayHello();
//        userController2.sayHello();
//        userController3.sayHello();
//
//        UserRepository userRepository = context.getBean(UserRepository.class);
//        userRepository.sayHello();
//
//        UserComponent userComponent = context.getBean("userComponent", UserComponent.class);
//        userComponent.sayHello();
//
//        UserConfiguration userConfiguration = (UserConfiguration) context.getBean("userConfiguration");
//        userConfiguration.sayHello();
//
//        // 从 Spring上下文中获取对象
////        User user = context.getBean(User.class);
////        System.out.println(user);
////        User user1 = (User) context.getBean("user1");
//        User u1 = (User) context.getBean("u1");
//        User user2 = (User) context.getBean("user2");
//        System.out.println(u1);
////        System.out.println(user1);
//        System.out.println(user2);






















    }

}
